namespace B.S.Data.MES.API.Models
{
    /// <summary>
    /// 科大讯飞聊天请求
    /// </summary>
    public class XunFeiChatRequest
    {
        public XunFeiHeader Header { get; set; } = new();
        public XunFeiParameter Parameter { get; set; } = new();
        public XunFeiPayload Payload { get; set; } = new();
    }

    /// <summary>
    /// 科大讯飞请求头
    /// </summary>
    public class XunFeiHeader
    {
        public string app_id { get; set; } = string.Empty;
        public string uid { get; set; } = string.Empty;
    }

    /// <summary>
    /// 科大讯飞参数
    /// </summary>
    public class XunFeiParameter
    {
        public XunFeiChat Chat { get; set; } = new();
    }

    /// <summary>
    /// 科大讯飞聊天参数
    /// </summary>
    public class XunFeiChat
    {
        public string domain { get; set; } = "generalv3";
        public double temperature { get; set; } = 0.5;
        public int max_tokens { get; set; } = 1024;
    }

    /// <summary>
    /// 科大讯飞载荷
    /// </summary>
    public class XunFeiPayload
    {
        public XunFeiMessage Message { get; set; } = new();
    }

    /// <summary>
    /// 科大讯飞消息
    /// </summary>
    public class XunFeiMessage
    {
        public List<XunFeiMessageItem> Text { get; set; } = new();
    }

    /// <summary>
    /// 科大讯飞消息项
    /// </summary>
    public class XunFeiMessageItem
    {
        public string role { get; set; } = string.Empty;
        public string content { get; set; } = string.Empty;
    }

    /// <summary>
    /// 科大讯飞响应
    /// </summary>
    public class XunFeiChatResponse
    {
        public XunFeiResponseHeader Header { get; set; } = new();
        public XunFeiResponsePayload Payload { get; set; } = new();
    }

    /// <summary>
    /// 科大讯飞响应头
    /// </summary>
    public class XunFeiResponseHeader
    {
        public int code { get; set; }
        public string message { get; set; } = string.Empty;
        public string sid { get; set; } = string.Empty;
        public int status { get; set; }
    }

    /// <summary>
    /// 科大讯飞响应载荷
    /// </summary>
    public class XunFeiResponsePayload
    {
        public XunFeiResponseChoices Choices { get; set; } = new();
        public XunFeiResponseUsage Usage { get; set; } = new();
    }

    /// <summary>
    /// 科大讯飞响应选择
    /// </summary>
    public class XunFeiResponseChoices
    {
        public int status { get; set; }
        public int seq { get; set; }
        public List<XunFeiResponseText> text { get; set; } = new();
    }

    /// <summary>
    /// 科大讯飞响应文本
    /// </summary>
    public class XunFeiResponseText
    {
        public string content { get; set; } = string.Empty;
        public string role { get; set; } = string.Empty;
        public int index { get; set; }
    }

    /// <summary>
    /// 科大讯飞使用统计
    /// </summary>
    public class XunFeiResponseUsage
    {
        public XunFeiResponseText Text { get; set; } = new();
    }

    /// <summary>
    /// AI智能助手请求
    /// </summary>
    public class AIAssistantRequest
    {
        public string Message { get; set; } = string.Empty;
        public string SessionId { get; set; } = string.Empty;
        public int? UserId { get; set; }
        public List<ConversationHistory>? History { get; set; }
    }

    /// <summary>
    /// AI智能助手响应
    /// </summary>
    public class AIAssistantResponse
    {
        public string Response { get; set; } = string.Empty;
        public string SessionId { get; set; } = string.Empty;
        public List<string> Suggestions { get; set; } = new();
        public string DataType { get; set; } = string.Empty;
        public int DataCount { get; set; }
        public bool HasData { get; set; }
        public long ProcessingTime { get; set; }
    }

    /// <summary>
    /// 对话历史
    /// </summary>
    public class ConversationHistory
    {
        public string Role { get; set; } = string.Empty;
        public string Content { get; set; } = string.Empty;
        public DateTime Timestamp { get; set; }
    }

    // ========== 新的HTTP API模型类 ==========

    /// <summary>
    /// 科大讯飞HTTP API请求模型
    /// </summary>
    public class XunFeiHttpRequest
    {
        /// <summary>
        /// 最大token数
        /// </summary>
        public int max_tokens { get; set; } = 4096;

        /// <summary>
        /// 温度参数
        /// </summary>
        public double temperature { get; set; } = 0.5;

        /// <summary>
        /// 消息列表
        /// </summary>
        public List<XunFeiHttpMessage> messages { get; set; } = new();

        /// <summary>
        /// 模型名称
        /// </summary>
        public string model { get; set; } = "4.0Ultra";

        /// <summary>
        /// 是否启用流式响应
        /// </summary>
        public bool stream { get; set; } = false;
    }

    /// <summary>
    /// 科大讯飞HTTP API消息
    /// </summary>
    public class XunFeiHttpMessage
    {
        /// <summary>
        /// 角色：system, user, assistant
        /// </summary>
        public string role { get; set; } = string.Empty;

        /// <summary>
        /// 消息内容
        /// </summary>
        public string content { get; set; } = string.Empty;
    }

    /// <summary>
    /// 科大讯飞HTTP API响应模型
    /// </summary>
    public class XunFeiHttpResponse
    {
        /// <summary>
        /// 响应ID
        /// </summary>
        public string id { get; set; } = string.Empty;

        /// <summary>
        /// 对象类型
        /// </summary>
        public string @object { get; set; } = string.Empty;

        /// <summary>
        /// 创建时间
        /// </summary>
        public long created { get; set; }

        /// <summary>
        /// 模型名称
        /// </summary>
        public string model { get; set; } = string.Empty;

        /// <summary>
        /// 选择列表
        /// </summary>
        public List<XunFeiHttpChoice> choices { get; set; } = new();

        /// <summary>
        /// 使用统计
        /// </summary>
        public XunFeiHttpUsage? usage { get; set; }
    }

    /// <summary>
    /// 科大讯飞HTTP API选择项
    /// </summary>
    public class XunFeiHttpChoice
    {
        /// <summary>
        /// 索引
        /// </summary>
        public int index { get; set; }

        /// <summary>
        /// 消息内容
        /// </summary>
        public XunFeiHttpMessage? message { get; set; }

        /// <summary>
        /// 增量内容（流式响应使用）
        /// </summary>
        public XunFeiHttpDelta? delta { get; set; }

        /// <summary>
        /// 完成原因
        /// </summary>
        public string? finish_reason { get; set; }
    }

    /// <summary>
    /// 科大讯飞HTTP API增量内容
    /// </summary>
    public class XunFeiHttpDelta
    {
        /// <summary>
        /// 角色
        /// </summary>
        public string? role { get; set; }

        /// <summary>
        /// 内容
        /// </summary>
        public string? content { get; set; }
    }

    /// <summary>
    /// 科大讯飞HTTP API使用统计
    /// </summary>
    public class XunFeiHttpUsage
    {
        /// <summary>
        /// 提示token数
        /// </summary>
        public int prompt_tokens { get; set; }

        /// <summary>
        /// 完成token数
        /// </summary>
        public int completion_tokens { get; set; }

        /// <summary>
        /// 总token数
        /// </summary>
        public int total_tokens { get; set; }
    }

    /// <summary>
    /// 流式响应数据项
    /// </summary>
    public class StreamResponseItem
    {
        /// <summary>
        /// 数据内容
        /// </summary>
        public string Data { get; set; } = string.Empty;

        /// <summary>
        /// 是否完成
        /// </summary>
        public bool IsComplete { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        public string? Error { get; set; }
    }
}

